Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config CLI argument to lint, fix, and parse #1986

Merged
merged 4 commits into from
Nov 27, 2021
Merged

Add config CLI argument to lint, fix, and parse #1986

merged 4 commits into from
Nov 27, 2021

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Nov 27, 2021

Brief summary of the change made

Fixes #1244.
This PR adds a command line argument --config to the CLI lint, fix, and parse commands.

The user can specify an additional config file such that the override logic is (later files override earlier ones):

  • default_config.cfg (package default)
  • <user_appdir_configs>
  • <user_homedir_configs>
  • <user_homedir_configs>
  • <configs_between_cwd_and_sql_path>
  • <extra_config_file> (this PR)
  • Any command line arguments

This behaviour was voted on in the Slack channel: https://sqlfluff.slack.com/archives/C01GPHR8J0G/p1637859667129900

If no config files are included in the default config search paths then this argument can be used to specify a single off-path config file which will also be useful for several applications.
(Will investigate in a future PR adding --ignore-local-config option to allow only --config to be considered)

N.B. This PR focuses on the CLI, I will make a subsequent PR to flow the changes through to the Simple API as well.

Are there any other side effects of this change that we should be aware of?

No

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with python test/generate_parse_fixture_yml.py or by running tox locally).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Nov 27, 2021

Codecov Report

Merging #1986 (997622b) into main (d145358) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1986   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          148       148           
  Lines        10292     10305   +13     
=========================================
+ Hits         10292     10305   +13     
Impacted Files Coverage Δ
src/sqlfluff/cli/commands.py 100.00% <100.00%> (ø)
src/sqlfluff/core/config.py 100.00% <100.00%> (ø)
src/sqlfluff/core/linter/linter.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d145358...997622b. Read the comment docs.

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but how do we know that the extra config is being used? Tests don't seem to check that.

Also test/fixtures/cli/extra_config_tsql.sql is empty which looks a little odd.

Maybe we could fix both concerns by adding some T-SQL specific SQL that fails in ANSI to check the dialect has indeed been changed as per the extra config?

@jpy-git
Copy link
Contributor Author

jpy-git commented Nov 27, 2021

@tunetheweb weird that's exactly what the test was! Not sure how it didn't commit that sql but will add it back in now 😄

@jpy-git
Copy link
Contributor Author

jpy-git commented Nov 27, 2021

@tunetheweb I've re-added that missing unit test back in 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add sqlfluff CLI option to pass the configuration files
2 participants